home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-09-26 | 2.8 KB | 148 lines | [TEXT/MPS ] |
- int (*tfs_alert)();
- int (*tfs_done)();
-
- char macfile[256]; /* for Macintosh file name translation */
-
- int ntftps = 0;
-
-
- int tfstate = OFF;
- long refusedt = 0; /* time of most recent transfer refusal */
-
- /* Setup a TFTP connection block. */
-
- tfmkcn(cn, dir, mode)
- register struct tfconn * cn;
- unsigned dir;
- unsigned mode;
- {
- cn->tf_fd = NULL;
- cn->tf_udp = NULL;
- cn->tf_rcv = NULL;
- cn->tf_snt = 0;
- cn->tf_ous = 0;
- cn->tf_ntmo = 0;
- cn->tf_rsnd = 0;
- cn->tf_dir = dir;
- cn->tf_mode = mode;
- cn->tf_size = 0L;
- cn->tf_K = Kinit;
- cn->tf_trt = T0;
- cn->tf_rt = (long) min(cn->tf_trt * TMMULT, MAXTMO);
- cn->tf_NR = 0;
- cn->tf_NR_last = 1;
-
- cn->tf_tm = tm_alloc();
- if (cn->tf_tm == NULL) {
- error("TFTP: Couldn't allocate timer");
- return(-1);
- }
- cn->tf_outp = malloc(NORMLEN);
- if (cn->tf_outp == NULL) {
- error("TFTP: Couldn't allocate output packet");
- tm_free(cn->tf_tm);
- return(-2);
- }
- return(0);
- }
-
-
- /* Send a TFTP data block */
-
- tfsndata(cn, len)
- register struct tfconn *cn;
- unsigned len;
- {
- register struct tfdata *tfdata;
-
- tfdata = cn->tf_outp;
- tfdata->tf_op = DATA;
- tfdata->tf_block = cn->tf_expected;
-
- #ifdef TFTPDEBUG
- if (NDEBUG & APTRACE)
- printf("TFTP: sending block %u\n", tfdata->tf_block);
- #endif
- return(tf_write(cn, sizeof(struct tfdata) - 512 + len));
- }
-
- /* Process an incoming error packet */
-
- tfdoerr(cn, perr, len)
- register struct tfconn *cn;
- register struct tferr *perr;
- unsigned len;
- {
- char terror[100];
-
- sprintf(terror, "TFTP: Error from host: \"%s\"", perr->tf_err);
- error(terror);
- }
-
-
- /* Format up and send out an initial request for a tftp connection. */
-
- tfsndreq(cn, fname)
- register struct tfconn *cn;
- char *fname;
- {
- register struct tfreq *ptreq;
- unsigned reqlen;
-
- ptreq = (struct tfreq *) cn->tf_outp;
- if (cn->tf_dir == GET)
- ptreq->tf_op = RRQ;
- else if (cn->tf_dir == PUT)
- ptreq->tf_op = WRQ;
- else {
- #ifdef TFTPDEBUG
- printf("TFSNDREQ: Bad direction %u.\n", cn->tf_dir);
- tfcndump(cn);
- if (NDEBUG & BUGHALT)
- cu_exit(1);
- #endif
- return(-1);
- }
-
- strcpy(&ptreq->tf_name[0], fname);
- if (cn->tf_mode == IMAGE || cn->tf_mode == TEST)
- strcpy(&ptreq->tf_name[0] + strlen(fname) + 1, "image");
- else if (cn->tf_mode == OCTET)
- strcpy(&ptreq->tf_name[0] + strlen(fname) + 1, "octet");
- else if (cn->tf_mode == ASCII)
- strcpy(&ptreq->tf_name[0] + strlen(fname) + 1, "netascii");
- else {
- #ifdef TFTPDEBUG
- printf("TFSNDREQ: Bad mode %u.\n", cn->tf_mode);
- tfcndump(cn);
- if (NDEBUG & BUGHALT)
- cu_exit(1);
- #endif
- return(-1);
- }
-
- #ifdef TFTPDEBUG
- if (NDEBUG & APTRACE)
- printf("TFTP: sending initial request\n");
- #endif
- return(tf_write(cn, sizeof(struct tfreq) + strlen(fname)));
- }
-
-
-
-
- static unsigned socket = 0;
-
- unsigned short udp_socket()
- {
- if (socket)
- return socket++;
-
- socket = cticks;
- if (socket < 1000)
- socket +=1000;
- return(socket++);
- }
-
-
-